
create procedure sp_add_product_to_aggregator 
	@prod_code varchar(12), 
	@aggr_code varchar(12), 
	@position int,
	@hi_prc float,
	@dt_beg date,
	@dt_end date,
	@params xml
as
begin
	set nocount on;

	declare @prod_id int, @aggr_id int;
	select @prod_id = null, @aggr_id = null

	select @prod_id = id from dbdata.dbo.products where code = @prod_code;
	select @aggr_id = id from dbdata.dbo.aggregators where code = @aggr_code;
	
	insert into dbdata.dbo.aggregator_products(product_id, aggregator_id, position, hi_prc, dt_beg, dt_end, params)
	values(@prod_id, @aggr_id, @position, @hi_prc, @dt_beg, @dt_end, @params);
end;
go

grant execute on sp_add_product_to_aggregator to Executer;